package university;
import university.exceptions.*;

import java.util.*;

/**
 * Class that describes Students in university
 * @author anatolii.bondarenko
 */
class Student extends People{
    private int numberOfFailedDisciplines;
    private List<Integer> examAssessments;
    private boolean resigned;
    private double scholarship;
    /**
     * Details of student
     * @param fn is first name
     * @param ln is last name
     * @param year is year of birth
     * @param month is month of birth
     * @param day is day of birth
     * @param sch is scholarship bonus at the start of studying
     */
    public Student(String fn, String ln, int year, int month, int day, double sch) throws InvalidDateException, EmptyStringException, InvalidScholarshipException {
		super(fn, ln, year, month, day);
		examAssessments = new ArrayList<Integer>(0);
		numberOfFailedDisciplines = 0;
        scholarship = sch;
        if (sch<0){
            throw new InvalidScholarshipException("Scholarship cannot be negative");
        }
	}

    /**
     * When Student passes the exam
     * @param r is the assessment of the exam
     */
    public void addAssessmentResult(int r) throws InvalidMarkException{
        if (r>5 || r<1){
            throw new InvalidMarkException("Exam marks must be from 1 to 5");
        }
		examAssessments.add(r);
	}

    /**
     * Gets list of exam assessments
     * @return list of assessments
     */
    public List<Integer> getExamAssessments() throws ListEmptyException {
        if (examAssessments.size()==0){
            throw new ListEmptyException("No assessments available for this student");
        }
        return examAssessments;
    }

    /**
     * Adds 1 to counter of failed disciplines, if number of failed disciplines is 3 or more student is resigned
     */
	public void addFailedDiscipline(){
		numberOfFailedDisciplines++;
        if (numberOfFailedDisciplines >= 3){
            resign();
        }
	}

    /**
     * Gets number of failed disciplines for current student
     * @return number of failed disciplines
     */
    public int getNumberOfFailedDisciplines(){
        return numberOfFailedDisciplines;
    }

    /**
     * Reduces 1 from counter of failed disciplines
     */

	public void reduceFailedDisciplines() throws NoFailedDisciplinesException{
		numberOfFailedDisciplines--;
        if (numberOfFailedDisciplines < 0){
            numberOfFailedDisciplines = 0;
            throw new NoFailedDisciplinesException("This student has no failed disciplines. Cannote reduce nuumber of them");
        }
	}

    /**
     * Resign the student
     */
    public void resign(){
		resigned = true;
	}

    public void restore(){
        resigned = false;
    }
    /**
     * Checks if Student is resigned
     * @return true if resigned
     */
    public boolean isResigned(){
		return resigned;		
	}

    /**
     * At the start of new semester all session results must be reset.
     */
    public void resetStudentResult(){
		numberOfFailedDisciplines = 0;
		examAssessments = new ArrayList<Integer>(0);
	}

    /**
     * Sets amount of scholarship bonus to student
     * @param sch is scholarship bonus
     */
    public void setScholarship(double sch) throws InvalidScholarshipException{
        if (sch<0){
            scholarship = 0;
            throw new InvalidScholarshipException("Scholarship cannot be negative. Setting scholarship to 0");
        }
        scholarship = sch;
    }

    /**
     * Gets amount of scholarship bonus of the student
     * @return amount of scholarship bonus to student
     */
    public double getScholarship(){
        return scholarship;
    }

}
